<template>
	<div>
		<div class="page-bar">
			<ul class="page-breadcrumb">
				<li>
					<span>部门管理</span>
				</li>
			</ul>
		</div>
		<el-form :inline="true" :model="formInline" class="demo-form-inline">
		  	<el-form-item label="部门名称">
			    <el-input v-model="formInline.departmentName" placeholder="部门名称"></el-input>
		  	</el-form-item>
		  	<el-form-item>
		    	<el-button type="primary" @click="onSubmit">查询<i class="el-icon-search el-icon--right"></i></el-button>
		  	</el-form-item>
		  	<el-button type="primary" class="xj" @click="clickFn">新建<i class="el-icon-plus el-icon--right"></i></el-button>
		</el-form>
		<el-table :data="departmentlist.records" style="width: 100%">
      		<el-table-column prop="orgName" label="部门名称">
      		</el-table-column>
      		<el-table-column prop="parentOrganization.orgName" label="上级部门">
      		</el-table-column>
      		<!-- <el-table-column prop="lx" label="类型">
      		</el-table-column> -->
      		<el-table-column prop="remark" label="备注">
      		</el-table-column>
      		<el-table-column prop="cz" label="操作" width="150">
      			<template scope="scope">
			        <el-button type="primary" size='small' @click="detailDepartment(scope.$index, scope.row)">修改</el-button>
			        <el-button type="danger" size='small' @click=" open2(scope.row)">删除</el-button>
			      </template>
      		</el-table-column>
    	</el-table>
    	<el-pagination
    	  v-if="departmentlist.totalPage>1"
    	  @current-change="handleCurrentChange"
	      :current-page="pageindex"
	      :page-count.sync="departmentlist.totalPage"
	      :page-size="pagesize"
	      layout="total, prev, pager, next"
	      :total="departmentlist.totalRecords">
	    </el-pagination>
    	<el-dialog
				title="提示"
				:visible.sync="visible"
				size="tiny">
			<span>确定删除？</span>
			<span slot="footer" class="dialog-footer">
		    <el-button @click="visible = false">取 消</el-button>
		    <el-button type="primary" @click="visible = false">确 定</el-button>
		  </span>
		</el-dialog>
	</div>

</template>

<script>
	import { DepartmentSrv } from './department.service';
    import { Notification } from 'element-ui';

	export default {
		data() {
			return {
				departmentlist: {},
				isopen: true,
				visible: false,
				pagesize:10,
				pageindex:1,
				formInline: {
                    departmentName: '',
		          	region: ''
		        }
			}
		},
		methods: {
			onSubmit() {//查询
                this.getDepartmentList();
	      	},
	      	detailDepartment(index, row) {//修改
	        	this.$router.push({name:'departmentmodification',params:{id:row.id}});
	      	},
	      	deleteDepartment( row) {//删除
                DepartmentSrv.deleteID(row).then((result) =>{
                    if(result.code === 0){

                        Notification.success({
                            title: "删除部门",
                            message: '操作成功',
                            offset: 50
                        })
                        this.getDepartmentList();

                    }
                })
	      	},
	      	clickFn:function(){//新建
	      		this.$router.push('/departmentcreation');
	      	},
	      	handleCurrentChange(val) {//分页
		        this.pageindex=val;
		        this.getDepartmentList();
		    },
	      	getDepartmentList(){
				var params = {
					pageNo:this.pageindex,
					pageSize:this.pagesize,
                    key:this.formInline.departmentName
				}
				DepartmentSrv.getDepartmentList(params).then((result) =>{
					if(result.code === 0){
						this.departmentlist = result.data;
					}
				})
			},
            open2(row) {
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
//                    this.$message({
//                        type: 'success',
//                        message: '删除成功!'
//                    });
                    this.deleteDepartment(row);



                }).catch(() => {
//                    this.$message({
//                        type: 'info',
//                        message: '已取消删除'
//                    });
                });
            }
		},
		created(){
			this.getDepartmentList();

		},
		mounted() {

		}
	}
</script>

<style scoped>
	.xj{
		float: right;
	}
	.el-form {
		margin-top: 10px;
	}
	.el-table th {
		text-align: center;
	}
</style>
